import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import printJS from 'print-js';
// import html2canvas from 'html2canvas';

@Component({
  selector: 'app-list',
  templateUrl: './list.component.html',
  styleUrls: ['./list.component.css']
})
export class ListComponent implements OnInit {

  constructor() { }

  ngOnInit(): void {
  }
  @ViewChild('tablelist') tablelist: ElementRef
  data = [
    {
      name:'张三',
      age:'18',
      gender:'男'
    },
    {
      name:'李四',
      age:'19',
      gender:'男'
    },
    {
      name:'王五',
      age:'20',
      gender:'女'
    },
  ]

  onPrint(){
    // html2canvas(this.tablelist.nativeElement,{
    //   useCORS:true,
    //   width: this.tablelist.nativeElement.scrollWidth,
    //   height: this.tablelist.nativeElement.scrollHeight
    // }).then((canvas)=>{
    //   printJS({
    //     printable: canvas,
    //     type: 'html',
    //   });
    // })
    printJS({
      printable: 'list', //list 表格 
      type: 'html',
      css: '/assets/css/print.css',
    });
    
  }

}
